package com.zzyl.nursing.controller.member;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;

import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;


    /**
     * 查询当天取消预约数量
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public AjaxResult cancelledCount(){
        return reservationService.cancelledCount();
    }
    /**
     * 查询每个时间段剩余预约次数
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public AjaxResult countByTime(Long time){

        return reservationService.countByTime(time);
    }

    /**
     * 分页查询预约
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询预约")
    public AjaxResult list(Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return success(getDataTable(list));
    }


    /**
     * 新增预约信息
     */
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation)
    {
        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult edit(@PathVariable Long id)
    {
        return toAjax(reservationService.updateReservation(id));
    }

}
